<?php
//后台管理员登录与退出模块
class LoginControl extends Control{
	private $_db;
	public function __init(){
		$this->_db=M('admin');
	}
	public function logout(){
		session(NULL);
		$this->success('退出成功','index');
	}
    public function index(){
		if(session('uid')){
			go("Index/index");
		}
		if(IS_POST){
			$username=Q("post.username");
			if(!$user=$this->_db->where("username='$username'")->find()){
				$this->error('帐号输入错误');
			}
			if($user['password']!=md5($_POST['password'])){
				$this->error('密码输入错误');
			}
			$_SESSION['uid']=$user['uid'];
			$_SESSION['username']=$user['username'];
			go('Index/index');
		}else{
		$this->display();
	   }
    }
	public function code(){
		$code = new Code();
		$code->show();
	}
	public function checkCode(){
		$stat = strtoupper($_POST['code'])==$_SESSION['code']?1:0;
		$this->ajax($stat);
	}
}
?>